package com.asion.vmovie.ui.MVPModel;

import com.asion.vmovie.api.ApiService;
import com.asion.vmovie.beans.CateDetials;
import com.asion.vmovie.ui.MVPContract.VideoContract;
import com.asion.vmovie.utils.retrofitCache.SetCacheUtils;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by asion on 16-10-21.
 */

public class VideoModel implements VideoContract.Model {
    @Override
    public void getCateDetials(int postid,VideoContract.OnGetCateDetials onGetCateDetials) {
        Observable<CateDetials> detial = new Retrofit.Builder().addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .client(SetCacheUtils.setCache())
                .baseUrl(ApiService.BASE_URL)
                .build()
                .create(ApiService.class)
                .getBannerDetial(postid);

        detial.subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(cateDetials -> onGetCateDetials.onGetSuccess(cateDetials),
                        throwable -> onGetCateDetials.onGetError(throwable));
    }
}
